<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="../../../../header.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css"
	href="/mutiselect/multiselectSrc/jquery.multiselect.css" />
<link rel="stylesheet" type="text/css"
	href="/mutiselect/assets/style.css" />
<link rel="stylesheet" type="text/css"
	href="/mutiselect/assets/prettify.css" />
<link rel="stylesheet" type="text/css"
	href="/css/jquery-ui.css" />
<script type="text/javascript" src="/js/jquery-1.7.1.js"></script>

<script type="text/javascript" src="/mutiselect/ui/jquery.ui.core.js"></script>
<script type="text/javascript" src="/mutiselect/ui/jquery.ui.widget.js"></script>
<script type="text/javascript" src="/mutiselect/assets/prettify.js"></script>
<script type="text/javascript" src="/mutiselect/multiselectSrc/jquery.multiselect.js"></script>

<script type="text/javascript">
	$(function() {
	
	});
	function showValues() {
		var valuestr = $("#sela").multiselect("MyValues");
		alert(valuestr);
	}
</script>
<style>
#manage-form {
	display: table;
}

.table-row {
	display: table-row;
}

.table-row>* {
	display: table-cell;
	margin-left: 20px;
	margin-top: 5px;
}
</style>
<script type="text/javascript">
	var primaryId;
	var username;
	$.ajax({
		type : "POST",
		url : "getAllUnRegistPerson",
		success : function(data) {
			var content = data;
			$("#sela").append(data);	
			$("select").multiselect({
				noneSelectedText : "==请选择==",
				checkAllText : "全选",
				uncheckAllText : '全不选',
				selectedList : 4
			});
		}
	});
	
</script>
</head>
<body style="align: center;">
	<div style="margin-top: 10px; margin-left: 30px;">
		<form id="manage-form" action="">
			<div class="table-row">
				<label for="jobcode">员工:</label><select id="sela" title="Basic example" multiple="multiple"
					name="example-basic" size="5">
				</select>
			</div>
			<div class="table-row">
				<label for="jobcode">密码:</label> <input type="text" class="ui-input"
					name="tradename" id="password">
			</div>
		</form>
	</div>

	<script type="text/javascript">
		var api = frameElement.api;
		var operate = api.data.operate;
		var rowid = api.data.rowid;
		var rowdata = api.data.rowdata;
		var CallBack = api.data.callback;
		$(function() {
			initPopBtns();
			if (operate == "edit") {
				$("#companyname").val(rowdata.companyname);
				$("#usercode").val(rowdata.usercode);
				$("#username").val(rowdata.username);
				$("#password").val(rowdata.password);
				$("#email").val(rowdata.email);
				$("#mobile").val(rowdata.mobile);
				$("#weixin").val(rowdata.weixin);
				$("#qq").val(rowdata.qq);
				$("#remark").val(rowdata.remark);
				$("#active").val(rowdata.active);
			}
		})
		function initPopBtns() {
			var btnname = "add" == operate ? [ "保存", "关闭" ] : [ "确定", "取消" ];
			api.button({
				id : "confirm",
				name : btnname[0],
				focus : true,
				callback : function(e) {
					var valuestr = $("#sela").multiselect("MyValues");
					var password = $("#password").val();
					if (operate == "addmore") {
						$.ajax({
							url : '/editEmploy?oper=addmore',
							type : 'POST',
							dataType : "json",
							data : {
								"persons" : valuestr,
								"password" : password,
								"active" : "1"
							},
							async : false,
							success : function(data) {
								if (data.status == 200) {
									parent.Public.tips({
										content : "添加成功"
									})
									CallBack();
								} else {
									if (data.status == 400) {
										parent.Public.tips({
											type : 1,
											content : "该编码的用戶已經存在"
										})
									} else {
										parent.Public.tips({
											type : 1,
											content : "添加失败:" + data.msg
										})
									}
								}
							}
						});
					} else {
						$.ajax({
							url : encodeURI("/editEmploy?oper=edit"),
							type : "POST",
							data : {
								"id" : rowid,
								"companyname" : companyname,
								"username" : username,
								"usercode" : usercode,
								"password" : password,
								"email" : email,
								"mobile" : mobile,
								"weixin" : weixin,
								"qq" : qq,
								"remark" : remark,
								"active" : active
							},
							async : false,//同步,坑爹啊。。
							success : function(data) {
								if (data.status == 200) {
									parent.Public.tips({
										content : "修改成功"
									})
									CallBack();
								} else if (data.status == 500) {
									parent.Public.tips({
										type : 1,
										content : "修改失败,该字段已被引用"
									})
								} else {
									parent.Public.tips({
										type : 1,
										content : "修改失败,用戶編碼已經存在"
									})
								}
							}
						});
					}
				}
			}, {
				id : "cancel",
				name : btnname[1]
			})
		}
	</script>
</body>
</html>